package com.cib.record.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @描述:
 * @Author: zhangh
 * @Time: 2021/5/13 11:31
 **/
public class ShellUtil {
    private static final Logger logger = LoggerFactory.getLogger(ShellUtil.class);
    public static void executeShell(String sh,String shellname){
        logger.info("start execute "+shellname+"!");
        try {
            String[] cmd={"sh","-c",sh};
            Runtime runtime=Runtime.getRuntime();
            Process exec = runtime.exec(cmd);

            int status = exec.waitFor();
            if (status!=0){
                logger.error(shellname+" failed,status返回状态错误。");
            }else{
                logger.info(shellname+" execute successful!");
            }
        }catch (Exception e){
            logger.error(shellname+"execute failed with throws:"+e.toString());
        }
    }
}
